package com.niit.gams.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.niit.gams.dao.SysUserMapper;
import com.niit.gams.pojo.SysUser;
import com.niit.gams.service.SysUserService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysUserServiceImpl implements SysUserService {
  private SysUserMapper sysUserMapper;

  public SysUserServiceImpl(SysUserMapper sysUserMapper) {
    this.sysUserMapper = sysUserMapper;
  }

  @Override
  public SysUser findUserByName(String name) {
    return sysUserMapper.findUserByName(name);
  }

  @Override
  public PageInfo<SysUser> findUsersByPage(Integer curPage, Integer pageSize) {
    PageHelper.startPage(curPage, pageSize);
    List<SysUser> userList = sysUserMapper.findUsersByPage(curPage, pageSize);
    PageInfo<SysUser> pageInfo = new PageInfo<>(userList);
    return pageInfo;
  }

  @Override
  public boolean addUser(SysUser user) {
    return sysUserMapper.insert(user) > 0;
  }

  @Override
  public boolean delUser(Integer id) {
    return sysUserMapper.deleteByPrimaryKey(id) > 0;
  }

  @Override
  public boolean updateUser(SysUser user) {
    return sysUserMapper.updateByPrimaryKey(user)>0;
  }
}
